
var initialState = {
    user: '',
    staffid:0,
    info:{},
    state:true
}

export default function reducer(state = initialState,action:any){
    //深拷贝state
    var newstate = JSON.parse( JSON.stringify( state ) )

    //判断action的类型
    if( action.type == 'SAVE_NAME' ){
        newstate.user = action.payload;
    }else if( action.type == 'REMOVE_NAME' ){
        newstate.user = '';
    }else if( action.type == 'SAVE_STAFFID' ){
        newstate.staffid = action.payload;
    }else if( action.type == 'INFO' ){
        newstate.info = action.payload
    }else if( action.type == 'STATE' ){
        newstate.state = false
    }else if(action.type == 'STATE2'){
        newstate.state = true
    }
    else {
          return state  
    }

    //返回全新的state
    return newstate;
}